package com.ruoyi.generator.service.impl;

import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.generator.mapper.ReverseGenTableColumnMapMapper;
import com.ruoyi.generator.domain.ReverseGenTableColumnMap;
import com.ruoyi.generator.service.IReverseGenTableColumnMapService;

/**
 * 反向生成字段映射Service业务层处理
 * 
 * @author Jason
 * @date 2022-02-09
 */
@Service
public class ReverseGenTableColumnMapServiceImpl implements IReverseGenTableColumnMapService 
{
    @Autowired
    private ReverseGenTableColumnMapMapper reverseGenTableColumnMapMapper;

    /**
     * 查询反向生成字段映射
     * 
     * @param mapId 反向生成字段映射ID
     * @return 反向生成字段映射
     */
    @Override
    public ReverseGenTableColumnMap selectReverseGenTableColumnMapById(Long mapId)
    {
        return reverseGenTableColumnMapMapper.selectReverseGenTableColumnMapById(mapId);
    }

    /**
     * 查询反向生成字段映射列表
     * 
     * @param reverseGenTableColumnMap 反向生成字段映射
     * @return 反向生成字段映射
     */
    @Override
    public List<ReverseGenTableColumnMap> selectReverseGenTableColumnMapList(ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        return reverseGenTableColumnMapMapper.selectReverseGenTableColumnMapList(reverseGenTableColumnMap);
    }

    /**
     * 通过ID组查询反向生成字段映射列表
     *
     * @param mapIds 需要查询的数据ID组
     * @return 反向生成字段映射集合
     */
    public List<ReverseGenTableColumnMap> selectReverseGenTableColumnMapListByIds(Long[] mapIds)
    {
        if(mapIds == null || mapIds.length == 0) {
            throw new CustomException("ID组为空");
        }
        return reverseGenTableColumnMapMapper.selectReverseGenTableColumnMapListByIds(mapIds);
    }

    /**
     * 新增反向生成字段映射
     *
     * @param reverseGenTableColumnMap 反向生成字段映射
     * @return 结果
     */
    @Override
    public int insertReverseGenTableColumnMap(ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        if(reverseGenTableColumnMap == null) {
            throw new CustomException("数据为空");
        }
        reverseGenTableColumnMap.setCreateTime(DateUtils.getNowDate());
        return reverseGenTableColumnMapMapper.insertReverseGenTableColumnMap(reverseGenTableColumnMap);
    }

    /**
     * 批量新增反向生成字段映射
     *
     * @param reverseGenTableColumnMapList 反向生成字段映射集合
     * @return 结果
     */
    @Transactional
    @Override
    public int insertReverseGenTableColumnMapListBatch(List<ReverseGenTableColumnMap> reverseGenTableColumnMapList)
    {
        if(reverseGenTableColumnMapList == null || reverseGenTableColumnMapList.size() == 0){
            return 0;
        }
        for(ReverseGenTableColumnMap reverseGenTableColumnMap : reverseGenTableColumnMapList) {
            reverseGenTableColumnMap.setCreateTime(DateUtils.getNowDate());
        }
        return reverseGenTableColumnMapMapper.insertReverseGenTableColumnMapListBatch(reverseGenTableColumnMapList);
    }

    /**
     * 修改反向生成字段映射
     * 
     * @param reverseGenTableColumnMap 反向生成字段映射
     * @return 结果
     */
    @Override
    public int updateReverseGenTableColumnMap(ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        if(reverseGenTableColumnMap == null) {
            throw new CustomException("数据为空");
        }
    reverseGenTableColumnMap.setUpdateTime(DateUtils.getNowDate());
        return reverseGenTableColumnMapMapper.updateReverseGenTableColumnMap(reverseGenTableColumnMap);
    }

    /**
     * 批量修改反向生成字段映射
     *
     * @param reverseGenTableColumnMapList 反向生成字段映射集合
     * @return 结果
     */
    @Transactional
    @Override
    public int updateReverseGenTableColumnMapListBatch(List<ReverseGenTableColumnMap> reverseGenTableColumnMapList)
    {
        if(reverseGenTableColumnMapList == null || reverseGenTableColumnMapList.size() == 0){
            return 0;
        }
        for(ReverseGenTableColumnMap reverseGenTableColumnMap : reverseGenTableColumnMapList) {
            reverseGenTableColumnMap.setUpdateTime(DateUtils.getNowDate());
        }
        return reverseGenTableColumnMapMapper.updateReverseGenTableColumnMapListBatch(reverseGenTableColumnMapList);
    }

    /**
     * 批量删除反向生成字段映射
     * 
     * @param mapIds 需要删除的反向生成字段映射ID
     * @return 结果
     */
    @Override
    public int deleteReverseGenTableColumnMapByIds(Long[] mapIds)
    {
        return reverseGenTableColumnMapMapper.deleteReverseGenTableColumnMapByIds(mapIds);
    }

    /**
     * 删除反向生成字段映射信息
     * 
     * @param mapId 反向生成字段映射ID
     * @return 结果
     */
    @Override
    public int deleteReverseGenTableColumnMapById(Long mapId)
    {
        return reverseGenTableColumnMapMapper.deleteReverseGenTableColumnMapById(mapId);
    }
}
